//
//  OrderDetailHeaderCell.m
//  MobileShoppingMall
//
//  Created by 冯传昌 on 2021/5/6.
//  Copyright © 2021 冯传昌. All rights reserved.
//

#import "OrderDetailHeaderCell.h"

@interface OrderDetailHeaderCell()<UIGestureRecognizerDelegate>

@property (nonatomic,strong) UIImageView *bgImgV;
@property (nonatomic,strong) UIImageView *statusImgV;
@property (nonatomic,strong) UILabel *statusLB;
@property (nonatomic,strong) UIView *addressBgV;
//发货信息相关
@property (nonatomic,strong) UIView *deliverBgView;
@property (nonatomic,strong) UIImageView *deliverImgV;
@property (nonatomic,strong) UILabel *deliverStatusLB;
@property (nonatomic,strong) UILabel *deliverStatusDetailLB;
@property (nonatomic,strong) UILabel *deliverTimeLB;
@property (nonatomic,strong) UIImageView *toDetailImgV;
//分隔线
@property (nonatomic,strong) UIView *dividingLineV;
//收货地址信息相关
@property (nonatomic,strong) UIView *shippingBgV;
@property (nonatomic,strong) UIImageView *shippingImgV;
@property (nonatomic,strong) UILabel *linkerLB;
@property (nonatomic,strong) UILabel *addressLB;

@end

@implementation OrderDetailHeaderCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = MainBackColor;
        self.contentView.backgroundColor = MainBackColor;
        
        [self initUI];
    }
    return self;
}

#pragma mark - setter
- (void)setModel:(OrderDetailModel *)model{
    _model = model;
    if (_model.items.count > 0) {
        self.statusLB.text = _model.status;
        NSString *imgName = [NSString stringWithFormat:@"订单_%@",_model.status];
        self.statusImgV.image = LoadImage(imgName);
        
        self.deliverTimeLB.text = _model.outdate;
        if ([_model.status isEqualToString:@"交易成功"]) {
            self.deliverStatusLB.text = @"已完成";
            self.deliverStatusDetailLB.text = @"您的商品已经运送完成";
        }
    }
}
- (void)setDeliverModel:(OrderDetailDeliverModel *)deliverModel{
    _deliverModel = deliverModel;
    if ([_deliverModel.province isEmpty] == NO && _deliverModel.province.length > 0) {
        
        self.linkerLB.text = [NSString stringWithFormat:@"%@  %@",_deliverModel.linker,_deliverModel.linkphone];
        self.addressLB.text = [NSString stringWithFormat:@"%@ %@ %@ %@",_deliverModel.province,_deliverModel.city,_deliverModel.region,_deliverModel.address];
        
        if (_deliverModel.tracknumber.length <= 0 || [_deliverModel.tracknumber isEmpty] == YES) {
            self.deliverBgView.hidden = YES;
            self.shippingBgV.top = 0;
            self.addressBgV.height = 100;
        }
        float height = self.addressBgV.bottom;
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            if (self.updateCellHeightBlock) {
                self.updateCellHeightBlock(height);
            }
        });
    }
}

#pragma mark - UI
-(void)initUI{
    [self.contentView addSubview:self.bgImgV];
    [self.contentView addSubview:self.statusImgV];
    [self.contentView addSubview:self.statusLB];
    [self.contentView addSubview:self.addressBgV];
    
    [self.addressBgV addSubview:self.deliverBgView];
    [self.deliverBgView addSubview:self.deliverImgV];
    [self.deliverBgView addSubview:self.deliverStatusLB];
    [self.deliverBgView addSubview:self.deliverStatusDetailLB];
    [self.deliverBgView addSubview:self.deliverTimeLB];
    [self.deliverBgView addSubview:self.dividingLineV];
    
    [self.addressBgV addSubview:self.shippingBgV];
    [self.shippingBgV addSubview:self.shippingImgV];
    [self.shippingBgV addSubview:self.linkerLB];
    [self.shippingBgV addSubview:self.addressLB];
}
#pragma mark - lazy
- (UIImageView *)bgImgV{
    if (!_bgImgV) {
        _bgImgV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 130)];
        _bgImgV.image = LoadImage(@"订单_详情顶部背景");
    }
    return _bgImgV;
}
- (UIImageView *)statusImgV{
    if (!_statusImgV) {
        _statusImgV = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth/2 - 50, 49, 21, 21)];
    }
    return _statusImgV;
}
- (UILabel *)statusLB{
    if (!_statusLB) {
        _statusLB = [[UILabel alloc] initWithFrame:CGRectMake(self.statusImgV.right + 5, self.statusImgV.top-3, 150, 28)];
        _statusLB.textColor = UIColor.whiteColor;
        _statusLB.font = FontSetWithWeight(20, 0.3f);
        _statusLB.textAlignment = NSTextAlignmentLeft;
    }
    return _statusLB;
}
- (UIView *)addressBgV{
    if (!_addressBgV) {
        _addressBgV = [[UIView alloc] initWithFrame:CGRectMake(0, 118, ScreenWidth, 200)];
        _addressBgV.clipsToBounds = YES;
        _addressBgV.layer.cornerRadius = 12;
        _addressBgV.backgroundColor = UIColor.whiteColor;
    }
    return _addressBgV;
}
//发货地相关
- (UIView *)deliverBgView{
    if (!_deliverBgView) {
        _deliverBgView = [[UIView alloc] initWithFrame:CGRectMake(12, 20, ScreenWidth-24, 100)];
        _deliverBgView.backgroundColor = UIColor.whiteColor;
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(deliverDetailClick:)];
        tap.delegate = self;
        _deliverBgView.userInteractionEnabled = YES;
        [_deliverBgView addGestureRecognizer:tap];
    }
    return _deliverBgView;
}
- (UIImageView *)deliverImgV{
    if (!_deliverImgV) {
        _deliverImgV = [[UIImageView alloc] initWithFrame:CGRectMake(8, 4, 22, 20)];
        _deliverImgV.image = LoadImage(@"订单_发货");
    }
    return _deliverImgV;
}
- (UILabel *)deliverStatusLB{
    if (!_deliverStatusLB) {
        _deliverStatusLB = [[UILabel alloc] initWithFrame:CGRectMake(self.deliverImgV.right + 5, self.deliverImgV.top-1, 120, 22)];
        _deliverStatusLB.textColor = MainBlackTextColor;
        _deliverStatusLB.font = FontSetWithWeight(16, 0.2f);
        _deliverStatusLB.textAlignment = NSTextAlignmentLeft;
        _deliverStatusLB.text = @"发货中";
    }
    return _deliverStatusLB;
}
- (UILabel *)deliverStatusDetailLB{
    if (!_deliverStatusDetailLB) {
        _deliverStatusDetailLB = [[UILabel alloc] initWithFrame:CGRectMake(self.deliverImgV.right + 5, self.deliverStatusLB.bottom+3, ScreenWidth - 90, 20)];
        _deliverStatusDetailLB.textColor = MainPureColor(85);
        _deliverStatusDetailLB.font = FontSet(14);
        _deliverStatusDetailLB.textAlignment = NSTextAlignmentLeft;
        _deliverStatusDetailLB.text = @"商品已经在运输途中，请耐心等待";
    }
    return _deliverStatusDetailLB;
}
- (UILabel *)deliverTimeLB{
    if (!_deliverTimeLB) {
        _deliverTimeLB = [[UILabel alloc] initWithFrame:CGRectMake(self.deliverImgV.right + 5, self.deliverStatusDetailLB.bottom+2, ScreenWidth - 90, 17)];
        _deliverTimeLB.textColor = MainGrayTextColor;
        _deliverTimeLB.font = FontSet(12);
        _deliverTimeLB.textAlignment = NSTextAlignmentLeft;
    }
    return _deliverTimeLB;
}
- (UIImageView *)toDetailImgV{
    if (!_toDetailImgV) {
        _toDetailImgV = [[UIImageView alloc] initWithFrame:CGRectMake(self.deliverBgView.width - 18, self.deliverStatusDetailLB.top + 5, 6, 10)];
        _toDetailImgV.image = LoadImage(@"个人中心_查看全部");
    }
    return _toDetailImgV;
}
- (UIView *)dividingLineV{
    if (!_dividingLineV) {
        _dividingLineV = [[UIView alloc] initWithFrame:CGRectMake(33, 99, ScreenWidth - 33 - 15, 1)];
        _dividingLineV.backgroundColor = MainPureColor(240);
    }
    return _dividingLineV;
}

//收货地相关
- (UIView *)shippingBgV{
    if (!_shippingBgV) {
        _shippingBgV = [[UIView alloc] initWithFrame:CGRectMake(12, 100, ScreenWidth-24, 100)];
        _shippingBgV.backgroundColor = UIColor.whiteColor;
    }
    return _shippingBgV;
}
- (UIImageView *)shippingImgV{
    if (!_shippingImgV) {
        _shippingImgV = [[UIImageView alloc] initWithFrame:CGRectMake(8, 18, 22, 20)];
        _shippingImgV.image = LoadImage(@"订单_收货");
    }
    return _shippingImgV;
}

- (UILabel *)linkerLB{
    if (!_linkerLB) {
        _linkerLB = [[UILabel alloc] initWithFrame:CGRectMake(self.shippingImgV.right + 5, 18, ScreenWidth - 90, 20)];
        _linkerLB.textColor = MainBlackTextColor;
        _linkerLB.font = FontSet(15);
        _linkerLB.textAlignment = NSTextAlignmentLeft;
    }
    return _linkerLB;
}
- (UILabel *)addressLB{
    if (!_addressLB) {
        _addressLB = [[UILabel alloc] initWithFrame:CGRectMake(self.shippingImgV.right + 5, self.linkerLB.bottom + 8, ScreenWidth - 90, 40)];
        _addressLB.numberOfLines = 2;
        _addressLB.textColor = MainPureColor(85);
        _addressLB.font = FontSet(14);
        _addressLB.textAlignment = NSTextAlignmentLeft;
    }
    return _addressLB;
}
#pragma mark - SEL
-(void)deliverDetailClick:(UIGestureRecognizer *)ges{
    
}


@end
